<!-- Modal -->
<#include "../../select.ftl" />
<div class="modal-dialog wide" style="width: 550px;">
    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
            <h4 class="modal-title" id="myModalLabel">
            <#if upDocument??>
                <#if upDocument.id??>
                    编辑
                <#else>
                    新增
                </#if>
            </#if>
            </h4>
        </div>
        <div class="modal-body">
            <div id="errorMessage"><#include "../../message.ftl" /></div>
            <form class="form-horizontal" role="form" id="upDocumentForm" method="post" enctype="multipart/form-data"
                  action="${absoluteContextPath}/up/upDocument/save">
            <#if upDocument??>
                <#if upDocument.id??>
                    <input type="hidden" name="id" value="${upDocument.id?c}"/>
                <#else>
                    <input type="hidden" name="id" value=""/>
                </#if>
            </#if>
                <div class="row">

                    <div class="form-group col-md-12">
                        <label class="col-sm-4 control-label">分类</label>
                        <div class="col-sm-6">
                        <@select name="spareA" value="${upDocument.spareA!''}" list=sortTypeList class="form-control"/>
                        </div>
                    </div>
                    <div class="form-group col-md-12">
                        <label class="col-sm-4 control-label">子分类</label>
                        <div class="col-sm-6">
                        <@select name="spareB" value="${upDocument.spareB!''}" list=subcategoryTypeList class="form-control"/>
                        </div>
                    </div>
                    <div class="form-group col-md-12">
                        <label class="col-sm-4 control-label">标题</label>
                        <div class="col-sm-6">
                            <input name="subject" value="${upDocument.subject!''}" type="text" class="form-control"/>
                        </div>
                    </div>
                    <div class="form-group col-md-12">
                        <label class="col-sm-4 control-label">内容摘要</label>
                        <div class="col-sm-6">
                            <textarea name="synopsis" value="${upDocument.synopsis!''}" type="text"
                                      class="form-control"/>
                        </div>
                    </div>
                    <div class="form-group col-md-12">
                        <label class="col-sm-4 control-label"></label>
                        <div class="col-sm-6">
                            <input type="file" name="file" value="" / >


                        </div>
                    </div>

                </div>
            </form>
        </div>
        <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal" aria-hidden="true">关闭</button>
            <button type="button" class="btn btn-primary" onclick="save();">保存</button>
        </div>
    </div>
</div>
<script>
    $(function () {
        //指标大类联动指标小类
        $("#upDocumentForm").find("select[name=spareA]").chosen({disable_search_threshold: 10}).change(function () {
            var typeClass = $(this).val();
            var data = {};
            data.typeClass = typeClass;
            $.ajax({
                url: "${absoluteContextPath}/up/upDocument/getSpareB",
                type: 'post',
                data: data,
                success: function (data) {
                    var data = JSON.parse(data);
                    $("#upDocumentForm").find("select[name=spareB]").find("option").each(function () {
                        if ($(this).attr("value") != "") {
                            $(this).remove();
                        }
                    });
                    for (var index = 0; index < data.length; index++) {
                        spareB = data[index];
                        var option = "<option value='" + spareB.value + "'>" + spareB.content + "</option>";
                        $("#upDocumentForm").find("select[name=spareB]").append(option);
                    }
                    $("#upDocumentForm").find("select[name=spareB]").chosen().trigger('chosen:updated');
                    ;
                }
            });
        });

    });

/*      function onc(){
          var files = document.getElementById("input").files;
          var cs = document.getElementById("cs");
          for(var i=0; i< files.length; i++){
              console.info(files[i]);
              cs.filters=files[i];
              console.info( "ADS"  ,cs.filters);
          }
      }*/
    function save() {
        $("#" + "upDocumentForm").ajaxSubmit({
            success: function (data) {
                data = JSON.parse(data);
                if (data.returnCode == 1) {
                    $('#myModal').modal("hide");
                    $.showMessage({parentId: "showMessage", message: "信息保存成功！", type: "success"});
                    refreshTable();
                } else {
                    $.showMessage({
                        parentId: "errorMessage",
                        message: "<strong>错误信息</strong>：" + data.returnMsg,
                        type: "error"
                    });
                }
            }
        });
    }
</script>